package com.itany.corejava.day14;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;

public class TestObjectIOStream {


    public static void main(String[] args) {


        Person p1=new Person();
        p1.setId(1);
        p1.setName("abc");
        p1.setAge(23);

        Address address=new Address();
        address.setCity("南京市");

        p1.setAddress(address);

        System.out.println(p1);
        System.out.println(p1.getAddress());

        byte[] b=SerializableUtil.encoderObject(p1);



        Person p2= (Person) SerializableUtil.decoderObject(b);

        System.out.println(p2);
        System.out.println(p2.getAddress());

        System.out.println(p2.getId());
        System.out.println(p2.getName());
        System.out.println(p2.getAge());
        System.out.println(p2.getAddress().getCity());











//
//
//        try(ObjectOutputStream oos=new ObjectOutputStream(
//                new FileOutputStream("d:/obj.dat")
//        )){
//
//
//            oos.writeObject(p1);
//
//
//
//
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }





//        try(ObjectInputStream ois=new ObjectInputStream(
//                new FileInputStream("d:/obj.dat")
//        )){
//
//            Person p2= (Person) ois.readObject();
//
//            System.out.println(p2.getId());
//            System.out.println(p2.getName());
//            System.out.println(p2.getAge());
//            System.out.println(p2.getAddress().getCity());
//
//        }catch (Exception e){
//            e.printStackTrace();
//        }





































    }


}
